<template>
  <div class="level">
    <h1>医院</h1>
    <div class="content">
      <div class="left">等级:</div>
      <ul class="hospital">
        <li :class="{active:isactive==-1}" @click="cliactive(-1,'')" >全部</li>
        <li :class="{active:isactive==index}" @click="cliactive(index,item)"  v-for="(item,index) in levelArr" :key="item.id">{{item.name}}</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang='ts'>

// 获取数据展示
import { reqHospitalLevelAndRegion } from "@/api/home";
import { onMounted, ref } from "vue";
import type { HospitalLevelAndRegionResponseData, HospitalLevelAndRegionArr} from "@/api/home/types";
import { defineEmits } from "vue";
onMounted(() => {
  getLevel();
});
const levelArr=ref<HospitalLevelAndRegionArr>()
//获取医院等级的数据
const getLevel = async () => {
  let result: HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion(
    "HosType"
  );
  //存储医院等级的数据
  if (result.code == 200) {
    levelArr.value = result.data;
  }
};

// 点击切换样式,发请求
const emits=defineEmits(["getLevel"])
const isactive=ref<number>(-1)
const cliactive=(index:number,item:any)=>{
  isactive.value=index;
  emits("getLevel",item.value)
}
</script>

<script lang="ts">
export default {
    name:"Level"
}
</script>

<style scoped lang="scss">
.level {
  color: #7f7f7f;
  margin-top: 20px;
  h1 {
    font-weight: 900;
    margin: 10px 0px;
  }
  .content {
    display: flex;
    .left {
      margin-right: 10px;
    }
    .hospital {
      display: flex;
      li {
        margin-right: 10px;
        &.active {
          color: #55a6fe;
        }
      }
      li:hover {
        color: #55a6fe;
        cursor: pointer;
      }
    }
  }
}
</style>
